package com.aigou.admin.service.impl;

import com.aigou.admin.dao.SearchDAO;
import com.aigou.admin.dao.impl.SearchDAOImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.Search;
import com.aigou.admin.service.SearchService;

import java.util.List;

public class SearchServiceImpl implements SearchService {

    //调用dao层对象
    private SearchDAO searchDAO = new SearchDAOImpl();


    @Override
    public PageEntity<Search> findSearchPage(Integer current, Integer pageSize) {
        //查询所有总数
        int total = searchDAO.selectSearchCount();
        //分页查询数据 limit
        List<Search> searches = searchDAO.selectSearchlimit((current-1)*pageSize,pageSize);
        //包装数据发送给前端
        PageEntity<Search> pageEntity = new PageEntity<>();
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setCurrent(current);
        pageEntity.setRecords(searches);
        return pageEntity;
    }

    @Override
    public List<Search> findAll() {
        return searchDAO.selectAll();
    }

    @Override
    public Search findById(String id) {
        return searchDAO.selectById(id);
    }

    @Override
    public boolean save(Search search) {
        return searchDAO.insert(search);
    }

    @Override
    public boolean remove(String id) {
        return searchDAO.delete(id);
    }

    @Override
    public boolean update(Search search) {
        return searchDAO.update(search);
    }
}
